{% extends "mp_base.html"%}
{% load commonFilters %}
{% load i18n %}

{% comment %}
copyright (c) 2009, paketka@gmail.com et. al
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

	* Redistributions of source code must retain the above copyright notice,
	  this list of conditions and the following disclaimer.

	* Redistributions in binary form must reproduce the above copyright notice,
	  this list of conditions and the following disclaimer in the documentation
	  and/or other materials provided with the distribution.

	* Neither the name of the <ORGANIZATION> nor the names of its contributors
	  may be used to endorse or promote products derived from this software
 	  without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{% endcomment %}

{% block keywords %}
poslanec, {{ mp.name }} {{ mp.surname }}, poslankyně, zvolené období, detail, {{ mp.term.getStart }} - {{ mp.term.getEnd }},
funkční období, jak jsem hlasoval
{% endblock %}
{% block css-links %}
	<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}/css/ui.jqgrid.css" />
{% endblock %}

{% block js-links %}
	{{ block.super }}
{% endblock %}

{% block javascript-head %}

{% comment %}
	accordCharts is a javascript array of records.
	each record looks as follows:
		{	url: 'an ajax url where from chart should be fetched',
			optName: 'Option name for selection list'
			imgCache: 'store img element here once it's been fetched by ajax
			groupId: group.id
		}
{% endcomment %}
var accordCharts = [
			{
				url: '',
				optName: '{% trans "Vyber skupinu" %}',
				imgCache: '',
				groupId: '',
				groupSlug: ''
			}
	{% for i in mships %}
		{% if forloop.first %}
			,
		{% endif %}
		{% if forloop.last %}
			{
				url: '{% url json.views.get_mp_accordance mp.id, i.group.id, dateStart.year, dateStart.month, dateStart.day, noActive, dateEnd.year, dateEnd.month, dateEnd.day %}',
			{% ifequal i.group.type "KLUB" %}
				optName: '{{ i.group.getPartyName }}',
			{% else %}
				optName: '{{ i.group.name|truncatewords:3 }}',
			{% endifequal %}
				imgCache: '',
				groupId: {{ i.group.id }},
				groupSlug: '{{ i.group.slug }}'
			}
		{% else %}
			{
				url: '{% url json.views.get_mp_accordance mp.id, i.group.id, dateStart.year, dateStart.month, dateStart.day, noActive, dateEnd.year, dateEnd.month, dateEnd.day %}',
			{% ifequal i.group.type "KLUB" %}
				optName: '{{ i.group.getPartyName }}',
			{% else %}
				optName: '{{ i.group.name|truncatewords:3 }}',
			{% endifequal %}
				imgCache: '',
				groupId: {{ i.group.id }},
				groupSlug: '{{ i.group.slug }}'
			},
		{% endif %}
	{% endfor %}
	{% for group in parties %}
		{% comment %}
			we need to to add a ',' since list continues with parties now
		{% endcomment %}
		{% if forloop.first %}
			,
		{% endif %}
		{% if forloop.last %}
			{
				url: '{% url json.views.get_mp_accordance mp.id, group.id, dateStart.year, dateStart.month, dateStart.day, noActive, dateEnd.year, dateEnd.month, dateEnd.day %}',
				optName: '{{ group.getPartyName }}',
				imgCache: '',
				groupId: {{ group.id }},
				groupSlug: '{{ group.slug }}'
			}
		{% else %}
			{
				url: '{% url json.views.get_mp_accordance mp.id, group.id, dateStart.year, dateStart.month, dateStart.day, noActive, dateEnd.year, dateEnd.month, dateEnd.day %}',
				optName: '{{ group.getPartyName }}',
				imgCache: '',
				groupId: {{ group.id }},
				groupSlug: '{{ group.slug }}'
			},
		{% endif %}
	{% endfor %}
];

function groupChanged(elemId)
{
	var baseUrl = '';

	var divId = elemId.replace(/-.*$/g,'');

	newIndex = $('#' + elemId)[0].selectedIndex;

	if (newIndex == 0)
		return;

	if (accordCharts[newIndex].imgCache.charAt(0) == "<") {
		$('#' + divId).html(accordCharts[newIndex].imgCache);
		newUrl = '?accordGroup=' + accordCharts[newIndex].groupSlug;
		$('#link-me').attr('href', newUrl);
	}
	else {
		$('#' + divId).html('<img src="{{ MEDIA_URL }}/images/wait.gif"/>');
		$.ajax({
				url : accordCharts[newIndex].url,
				async : true,
				dataType : 'json',
				success : function(data) {
						newUrl = '?accordGroup=' + accordCharts[newIndex].groupSlug;
						$('#link-me').attr('href', newUrl);
						$('#' + divId).html(data);
						accordCharts[newIndex].imgCache = data;
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
						$('#' + divId).html('<img src="{{ MEDIA_URL }}/images/error.gif"/>');
				}
		});
	}
}
{% endblock javascript-head %}

{% block document-ready %}
	
	{{ block.super }}

	for (i in accordCharts) {
		$('#accordanceCharts-control').append(
			'<option value="' + accordCharts[i].groupId + '">' + accordCharts[i].optName + '</option>'
		);
	}

{% endblock document-ready %}

{% block left-sidebar %}
	{% comment %}
	We want to get rid off poll calendar for MP' complete term overivew.
	Instead of calendar we want to offer visitor the choice of other MP's terms
	{% endcomment %}
	<div class="ui-widget">
		<div class="ui-widget-header">
			<h1>{% trans "Funkční období" %}</h1>
		</div>
		<div class="ui-widget-content">
			<div class="container">
				<ul>
				{% for t in terms %}
					<li>{{ t|safe }}</li>
				{% endfor %}
			</div>
		</div>
	</div>
{% endblock %}

{% block main-tab %}

<div class="ui-widget">
	<div class="ui-widget-header">
		<h2>{% trans "Členství v parlamentních organizacích" %}</h2>
	</div>
	<div class="ui-widget-content">
	<p style="font-size:0.9em">
		{% trans "V období" %} {{ mp.term.getStart }} - {{ mp.term.getEnd }} 
		{% trans "zasedám mimojiné i v těchto parlamentních skupinách a organizacích:" %}
	</p>
	{% for i in mships %}
		<div class="left" style="font-size:0.9em">
			<a href="{% url psp.views.show_group i.group.slug %}"> {{i.group.name}}</a>
		</div>
		<div class="right" style="font-size:0.9em">
			 [ {{ i.post }} {{ i.start|date:"Y m d" }} - {% if i.end %} {{ i.end|date:"Y m d" }} {% else %} {% now "Y m d" %} {% endif %}]
		</div>
		<div class="clear"></div>
		<p></p>
	{% endfor %}
	</ul>
	</div>
</div>

<div class="ui-widget">
	<div class="ui-widget-header">
		<h2>{% trans "Absence při hlasování" %}</h2>
	</div>
	<div class="ui-widget-content">
		<div class="left">
			{{ presenceChart.img|safe|mf:"presence-chart" }}
		</div>
		<div class="right">
			<p style="font-size:0.9em">
				{% with mp.name as mpName %}
				{% with mp.surname as mpSurname %}
				{% with term.getStart as termStart %}
				{% with term.getEnd as termEnd %}
				{% ifequal mp.sex "F" %}
				{% blocktrans %}
				Koláčový graf vpravo upekla poslankyně {{ mpName }} {{ mpSurname }}
				během svého působení ve sněmovně {{ termStart }} - {{ termEnd }}.
				Koláč se skládá ze tří přísad:
				{% endblocktrans %}
				{% else %}
				{% blocktrans %}
				Koláčový graf vpravo upekl poslanec {{ mpName }} {{ mpSurname }}
				během svého působení ve sněmovně {{ termStart }} - {{ termEnd }}.
				Koláč se skládá ze tří přísad:
				{% endblocktrans %}
				{% endifequal %}
				{% endwith %}
				{% endwith %}
				{% endwith %}
				{% endwith %}
			</p>
				<ul style="font-size:0.9em">
					<li>{% trans "Účast při hlasování:" %} {{ mp.votes.presencePerc|floatformat:2|mf:"presence" }}%</li>
					<li>{% trans "Omluvená neúčast:" %} {{ mp.votes.excusedPerc|floatformat:2|mf:"excused" }}%</li>
					<li>{% trans "Neomluvená neúčast" %} {{ mp.votes.absencesPerc|floatformat:2|mf:"absence" }}%</li>
				</ul>
			<p style="font-size:0.9em">
				{% trans "Celková neúčast (omluvená + neomluvená)" %} {{ mp.votes.totalAbsencesPerc|floatformat:2|mf:"total-absence" }}%
			</p>
		</div>
		<div class="clear"></div>
	</div>
</div>

<div class="ui-widget">
	<div class="ui-widget-header">
		<h2>{% trans "Shoda hlasování" %}</h2>
	</div>
	<div class="ui-widget-content">
		<div class="left">
			<div class="center" id="accordanceCharts">
				{{ accordanceChart.img|safe|mf:"accordance-chart" }}
				{{ activeAccordance.img|safe|mf:"active-accordnace-chart" }}
			{% if partyPie %}
				{{ partyPie.img|safe|mf:"party-pie" }}
			{% endif %}
			</div>
			<div class="center groupSelect">
				<select name="accordanceCharts" id="accordanceCharts-control" onChange="groupChanged(this.id)">
				</select>
			</div>
		</div>
		<div class="right">
			<p style="font-size:0.9em"> 
				{% blocktrans %}
				Koláčové grafy vlevo znázorňují shodu hlasování s vybranou stranou,
				či parlamentní organizací jejímž je
				{% endblocktrans %} {{ mp.name|mf:"name" }} {{ mp.surname|mf:"surname" }}
				{% ifequal mp.sex "F" %}
				{% trans "členkou" %}.
				{% else %}
				{% trans "členem" %}.
				{% endifequal %}
				{% blocktrans %}
				Výpočet pro horní graf nezohledňuje přítomnost/nepřítomnost
				{% endblocktrans %}
				{% ifequal mp.sex "F" %}
				{% trans "poslankyně" %}
				{% else %}
				{% trans "poslance" %}
				{% endifequal %}
				{% blocktrans %}
				během jednotlivých hlasování.
				{% endblocktrans %}
			<p style="font-size:0.9em"> {% blocktrans %}
				Druhý graf již s touto nepřítomností počítá. Všechna hlasování,
				kterých se
				{% endblocktrans %}
				{% ifequal mp.sex "F" %}
				{% trans "poslankyně nezúčastnila, " %}
				{% else %}
				{% trans "poslanec nezúčastnil, " %}
				{% endifequal %}
				{% trans "nejsou do výsledku započtena." %}
			</p>
			<p style="font-size:0.9em"> {% blocktrans %}
				Graf shody s jinou parlamentní skupinou vyberete z roletky pod grafy. V nabídce
				se objeví všechny stranické kluby a k tomu další parlementní organizace, kterými
				je
				{% endblocktrans %}
				{% ifequal mp.sex "F" %}
				{% trans "poslankyně členkou." %}
				{% else %}
				{% trans "poslanec členem." %}
				{% endifequal %}
				{% trans "Pro jiné než stranické kluby (např. " %} {{ mp.partyName }}
				{% blocktrans %}) bude vykreslen třetí graf: koláč znázorňující
				stranické složení vybrané skupiny.
				{% endblocktrans %}
			</p>
			<p style="font-size:0.9em">
			{% if accordGroup %}
				<a href="?accordGroup={{ accordGroupSlug }}" id="link-me">link</a>
			{% else %}
				<a href="" id="link-me">link</a>
			{% endif %}
			</p>
		</div>
		<div class="clear"></div>
	</div>
</div>

{% endblock main-tab %}

